package com.prs.crm.dao.oa.impl;
import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.oa.OaTaskKeyWordDao;
import com.prs.crm.domain.oa.OaTaskKeyWord;
import com.prs.crm.domain.sale.SalesContractDetail;
import com.prs.crm.domain.stock.ProductStore;

public class OaTaskKeyWordDaoImpl extends BaseDaoImpl<OaTaskKeyWord> implements
		OaTaskKeyWordDao {

	@Override
	public void saveOrUpdate(OaTaskKeyWord s) {
		this.getHibernateTemplate().saveOrUpdate(s);
		
	}

	@Override
	public OaTaskKeyWord getObjectOaTaskKeyWord(Serializable id) {
		// TODO Auto-generated method stub
		return this.getHibernateTemplate().get(OaTaskKeyWord.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public OaTaskKeyWord getOaTaskKeyWord(final int id) {
		return (OaTaskKeyWord)getHibernateTemplate().execute(   
			      new HibernateCallback() {   
			        public Object doInHibernate(Session session) throws HibernateException {   
			        	Criteria criteria =  session.createCriteria(OaTaskKeyWord.class);
			        	criteria.add(Restrictions.eq("id", id));
			        	List<OaTaskKeyWord> result = criteria.list();
			        	if (result.size()>0)
			        		return result.get(0);
			        	else
			        		return null;
			        }   
			      }   
			    );  
	}
	
    @SuppressWarnings("unchecked")
	@Override
	public int serchRep(final String Name) {
		return (Integer)getHibernateTemplate().execute(   
			      new HibernateCallback() {   
			        public Object doInHibernate(Session session) throws HibernateException {   
			        	Criteria criteria =  session.createCriteria(OaTaskKeyWord.class);
			        	criteria.add(Restrictions.eq("keyName", Name));
			        	List<OaTaskKeyWord> result = criteria.list();
			        	if (result.size()>0)
			        		return 1;
			        	else
			        		return 0;
			        }   
			      }   
			    );  
	}

	@SuppressWarnings("unchecked")
	@Override
	public OaTaskKeyWord getOaTaskKeyWordMany(final int jid,final String ids) {
		return (OaTaskKeyWord)getHibernateTemplate().execute(   
			      new HibernateCallback() {   
			        public Object doInHibernate(Session session) throws HibernateException {  
			        	List<OaTaskKeyWord>  bb=null;
			        String idString[]=ids.split(",");			        
			           for(int i=0;i<idString.length;i++){
			        		
			        	}
			        
			        	Criteria criteria =  session.createCriteria(OaTaskKeyWord.class);
//			        	criteria.add(Restrictions.eq("id", id));
			        	List<OaTaskKeyWord> result = criteria.list();
			        	if (result.size()>0)
			        		return result.get(0);
			        	else
			        		return null;
			        
			        
			        
			        
			        }   
			      }   
			    );  
	}

	
}
